/*
 * @Description: 雷达添加
 */
import BaseCommand from "@/core/Frame/BaseClass/BaseCommand";
const PIE = window.PIE;
const PIETWEEN = window.PIETWEEN;
const times = [0, 10000, 20000, 30000, 40000];
const points = [
    [115, 24.5, 70000],
    [116, 24.5, 70000],
    [117, 24.5, 70000],
    [118, 24.5, 70000],
    [119, 24.5, 70000],
];

class RadarAddCommand extends BaseCommand {
    viewer: any;
    globeControl: any;
    globe: any;
    workspace: any;
    spatialReference: any;
    constructor(params: any) {
        super();
        this.viewer = params.viewer;
        this.globeControl = this.viewer.getGlobeControl();
        this.globe = this.viewer.getGlobe();
        this.workspace = this.globe.getDocument();
        this.spatialReference = this.globe.getSpatialReference();
    };
    execute(option: any) {
        let renderableLayer = new PIE.GlobeRenderableLayer();
        this.globe.addLayer(renderableLayer, true);
        /**创建模型对象，添加在图层中**/
        let urlsFBX = [];
        urlsFBX.push('/src/assets/Texture/radar/radar.fbx');
        urlsFBX.push('/src/assets/Texture/radar/LD_01.jpg');
        urlsFBX.push('/src/assets/Texture/radar/LD_02.jpg');
        urlsFBX.push('/src/assets/Texture/radar/LD_04.jpg');
        let sceneCenter = new PIE.Vector2(100.6, 24.0);
        let posGlobeSR = this.spatialReference.forward(sceneCenter);
        let modelMesh = new PIE.ModelMesh();
        modelMesh.load({urls: urlsFBX}).then((value: any ) => {
            let model3D = new PIE.Model3D({modelMesh: modelMesh});
            model3D.setModelId(0);
            let position3d = new PIE.Vector3(posGlobeSR.x, posGlobeSR.y, 1000);
            let scale3d = new PIE.Vector3(7000, 7000, 7000);
            let rotation3d = new PIE.Vector3(-Math.PI / 2, 0, 0);
            let renderModel3D = new PIE.RenderModel({
                model: model3D,
                position: position3d,
                scale: scale3d,
                rotation: rotation3d,
            });
            renderableLayer.add(renderModel3D);
        })

        let radarMsg = new PIE.RadarMsg();//雷达信息传感器信息
        let options={x:posGlobeSR.x,y:posGlobeSR.y};
        let radarDisMsg = new PIE.RadarDisturbMsg(options);//干扰机

        let array=[117, 24.0];
        let posSr = this.spatialReference.forward(array);
        let radara = new PIE.RenderRadar();
        radara.load({position:[posSr[0], posSr[1],0], radarMsg:radarMsg, radarDisturbMsgs: [radarDisMsg],
            imageUrl: "/src/assets/Texture/RdarColortable.png", antennaImageUrl: "/src/assets/Texture/wave.png"}).then((value:any)=>{
            renderableLayer.add(radara);
        });

        array=[117, 25.0];
        posSr = this.spatialReference.forward(array);
        let radarb = new PIE.RenderRadar();
        radarb.load({position:[posSr[0], posSr[1],0], radarMsg:radarMsg, radarDisturbMsgs: [radarDisMsg],
            imageUrl: "/src/assets/Texture/RdarColortable.png", antennaImageUrl: "/src/assets/Texture/wave.png"}).then((value:any)=>{
            renderableLayer.add(radarb);
        });

        /**创建飞机模型对象，添加在图层中**/
        var urlsFlyFBX = [];
        urlsFlyFBX.push("data/F16/F16.fbx");
        urlsFlyFBX.push("data/F16/F16.jpg");
        sceneCenter = new PIE.Vector2(122, 24.0);
        posGlobeSR = this.spatialReference.forward(sceneCenter);
        modelMesh = new PIE.ModelMesh();
        modelMesh.load({urls: urlsFlyFBX}).then((value: any ) => {
            let model3D = new PIE.Model3D({modelMesh: modelMesh});
            model3D.setModelId(0);
            let position3d = new PIE.Vector3(posGlobeSR.x, posGlobeSR.y, 1000);
            let scale3d = new PIE.Vector3(7000, 7000, 7000);
            let rotation3d = new PIE.Vector3(-Math.PI / 2, 0, 0);
            let renderModel3D = new PIE.RenderModel({
                model: model3D,
                position: position3d,
                scale: scale3d,
                rotation: rotation3d,
            });
            renderableLayer.add(renderModel3D);
           let option= {times, points, renderModel3D, globeControl:this.globeControl};
            let  tweenSystem = new PIETWEEN.TweenModel(option );
            tweenSystem.start();
        })
        options={x:posGlobeSR.x,y:posGlobeSR.y};
        let radarDisturbMsg = new PIE.RadarDisturbMsg(options);//雷达干扰机

        options={x:posGlobeSR.x+4,y:posGlobeSR.y};
        let  radarDisturbMsga = new PIE.RadarDisturbMsg(options);//雷达干扰机

        radara.updateRadarBoxMsg(radarDisturbMsg);
        radara.updateRadarBoxMsg(radarDisturbMsga);

        radarb.updateRadarBoxMsg(radarDisturbMsg);
        radarb.updateRadarBoxMsg(radarDisturbMsga);
        option.checked = false;

    };
    release() {
        const { globeControl } = this;
        const { PIE } = window;
        globeControl.setGlobeTool(PIE.GlobeToolType.Pan);
    };
    isEnable() {
        return true;
    };

}

export default RadarAddCommand;
